/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
*
*
* Authors:                  zhoujian
* Email:            343600434@qq.com
* Date:         Jan-09-2024 15:42:24
*
*/

#include "gd32l23x.h"
#include "gd32l23x_eval.h"
#include "led.h"
#include "device.h"
#include "tim.h"
#include "gd32l23x_it.h"
#include "input.h"
#include "flash.h"
#include "stdio.h"
#include "speed_fifo.h"

#define LINURM_DEBUG_SPEED
//#define DEBUG_PRINTF
//uint16_t led_array[8][2] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint16_t led_array[4][4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

volatile uint8_t dis_mph;
uint8_t trip_odo = 0;

//#define TEST_SPI_SPEED
#ifdef TEST_SPI_SPEED
#warning("TEST SPI SPEED !!!!")
#endif
uint32_t get_dispaly_value(uint32_t v)
{
    if(dis_mph) {
        return (v * 1.60934);

    } else {
        return v;
    }
}

void update_mph_led(void)
{
    if(dis_mph == 1) {
        MPH_ON;
        KMPH_OFF;
        MILES_ON;
        MILES_LEFT_ON;
        KM_OFF;
        KM_LEFT_OFF;
        FT_OFF;
        FT_LEFT_OFF;

    } else if(dis_mph == 2) {
        MPH_ON;
        KMPH_OFF;
        MILES_OFF;
        MILES_LEFT_OFF;
        KM_OFF;
        KM_LEFT_OFF;
        FT_ON;
        FT_LEFT_ON;

    } else {
        MPH_OFF;
        KMPH_ON;
        MILES_OFF;
        MILES_LEFT_OFF;
        KM_ON;
        KM_LEFT_ON;
        FT_OFF;
        FT_LEFT_OFF;
    }
}

void update_trip_led(void)
{
    if(trip_odo) {
        TRIP_OFF;
        ODO_ON;

    } else {
        TRIP_ON;
        ODO_OFF;
    }
}

uint8_t is_odo(void)
{
    return trip_odo;
}

uint8_t is_mph(void)
{
    return dis_mph;
}


uint8_t update_led;

void toggle_trip_odo(void)
{
    //NVIC_SystemReset();
    if(trip_odo) {
        trip_odo = 0;

    } else {
        trip_odo = 1;
    }

    flash_info.sel = trip_odo;
    update_trip_led();
    update_led = 1;
    trip_odo_show();
    write_data_flash((uint32_t*)&flash_info);
    //trip_odo_handle();
    //save_odo_km_v();
}

void toggle_mph_display(void)
{
    if(dis_mph == 2) {
        dis_mph = 0;

    } else if(dis_mph == 1) {
        dis_mph = 2;

    } else {
        dis_mph = 1;
    }

    flash_info.sel = dis_mph;
    update_mph_led();
    update_trip_led();
    update_led = 1;
    trip_odo_show();
    write_data_flash((uint32_t*)&flash_info);
}



void spi0_init(void)
{
#ifdef MONI_SPI0
    rcu_periph_clock_enable(RCU_GPIOB);
    rcu_periph_clock_enable(RCU_GPIOA);
    gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_3 | GPIO_PIN_5);
    gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3 | GPIO_PIN_5);
    gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,  GPIO_PIN_15);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_15);
    SPI_SM16306S_LE_LOW;
#else
    spi_parameter_struct spi_init_struct;
    rcu_periph_clock_enable(RCU_GPIOB);
    rcu_periph_clock_enable(RCU_GPIOA);
    rcu_periph_clock_enable(RCU_SPI0);
    /* SPI0_CLK(PB3), SPI0_MISO_IO1(PB4), SPI0_MOSI_IO0(PB5),SPI0_IO2(PB6) and SPI0_IO3(PB7) GPIO pin configuration */
    gpio_af_set(GPIOB, GPIO_AF_5, GPIO_PIN_3 | GPIO_PIN_5);
    gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_3 | GPIO_PIN_5);
    gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3 | GPIO_PIN_5);
    /* SPI0_CS(PD2) GPIO pin configuration */
    gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,  GPIO_PIN_15);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_15);
    //gpio_bit_set(GPIOD, GPIO_PIN_2);
    /* chip select invalid */
    SPI_SM16306S_LE_LOW;
    /* SPI1 parameter config */
    spi_init_struct.trans_mode           = SPI_TRANSMODE_FULLDUPLEX;
    spi_init_struct.device_mode          = SPI_MASTER;
    spi_init_struct.frame_size           = SPI_FRAMESIZE_16BIT;
    spi_init_struct.clock_polarity_phase = SPI_CK_PL_LOW_PH_1EDGE;
    //spi_init_struct.clock_polarity_phase = SPI_CK_PL_HIGH_PH_1EDGE;
    //spi_init_struct.clock_polarity_phase = SPI_CK_PL_LOW_PH_2EDGE;
    //spi_init_struct.clock_polarity_phase = SPI_CK_PL_HIGH_PH_2EDGE;
    spi_init_struct.nss                  = SPI_NSS_SOFT;
#ifdef TEST_SPI_SPEED
    spi_init_struct.prescale             = SPI_PSC_32;
#else
    spi_init_struct.prescale             = SPI_PSC_2;
#endif
    spi_init_struct.endian               = SPI_ENDIAN_MSB;
    spi_init(SPI0, &spi_init_struct);
    /* configure SPI0 byte access to FIFO */
    spi_fifo_access_size_config(SPI0, SPI_HALFWORD_ACCESS);
    /* set crc polynomial */
    //spi_crc_polynomial_set(SPI0, 7);
    /* quad wire SPI_IO2 and SPI_IO3 pin output enable */
    //qspi_io23_output_enable(SPI0);
    /* enable SPI0 */
    spi_enable(SPI0);
#endif
}

void code38_init(void)
{
    rcu_periph_clock_enable(RCU_GPIOB);
    rcu_periph_clock_enable(RCU_GPIOA);
    gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,  GPIO_PIN_4);
    gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,  GPIO_PIN_4);
    gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_10 | GPIO_PIN_9);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10 | GPIO_PIN_9);
    OE_OFF;
    //rcu_periph_clock_enable(RCU_GPIOD);
    //gpio_mode_set(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,  GPIO_PIN_4);
    //gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_4);
}

//000
void sel_vcc(uint32_t i)
{
    if(i == 0) {
        GPIO_BC(GPIOA) = GPIO_PIN_10 | GPIO_PIN_9;
        //GPIO_BC(GPIOD) = GPIO_PIN_4;

    } else if(i == 1) {
        GPIO_BOP(GPIOA) = GPIO_PIN_10;
        GPIO_BC(GPIOA) = GPIO_PIN_9;
        //GPIO_BC(GPIOD) = GPIO_PIN_4;

    } else if(i == 2) {
        GPIO_BC(GPIOA) = GPIO_PIN_10;
        GPIO_BOP(GPIOA) = GPIO_PIN_9;
        //GPIO_BC(GPIOD) = GPIO_PIN_4;

    } else if(i == 3) {
        GPIO_BOP(GPIOA) = GPIO_PIN_10 | GPIO_PIN_9;
        //GPIO_BC(GPIOD) = GPIO_PIN_4;

    } else if(i == 4) {
        GPIO_BC(GPIOA) = GPIO_PIN_10 | GPIO_PIN_9;
        //GPIO_BOP(GPIOD) = GPIO_PIN_4;

    } else if(i == 5) {
        GPIO_BOP(GPIOA) = GPIO_PIN_10;
        GPIO_BC(GPIOA) = GPIO_PIN_9;
        //GPIO_BOP(GPIOD) = GPIO_PIN_4;

    } else if(i == 6) {
        GPIO_BC(GPIOA) = GPIO_PIN_10;
        GPIO_BOP(GPIOA) = GPIO_PIN_9;
        //GPIO_BOP(GPIOD) = GPIO_PIN_4;

    } else if(i == 7) {
        GPIO_BOP(GPIOA) = GPIO_PIN_10 | GPIO_PIN_9;
        //GPIO_BOP(GPIOD) = GPIO_PIN_4;
    }
}



void spi0_send(uint16_t data)
{
    //uint8_t i;
    //OE_OFF;
    SPI_SM16306S_LE_LOW;
#ifdef  MONI_SPI0
    uint8_t j;
    //GPIO_BOP(GPIOB) = GPIO_PIN_5;
    GPIO_BC(GPIOB) = GPIO_PIN_5;
    //GPIO_BOP(GPIOB) = GPIO_PIN_3;
    GPIO_BC(GPIOB) = GPIO_PIN_3;

    for(j = 16; j > 0; j++) {
        if((data >> (j - 1)) & 1) {
            GPIO_BOP(GPIOB) = GPIO_PIN_5;

        } else {
            GPIO_BC(GPIOB) = GPIO_PIN_5;
        }

        GPIO_BOP(GPIOB) = GPIO_PIN_3;
        GPIO_BC(GPIOB) = GPIO_PIN_3;
    }

    GPIO_BOP(GPIOB) = GPIO_PIN_5;
    GPIO_BOP(GPIOB) = GPIO_PIN_3;
    //GPIO_BC(GPIOB) = GPIO_PIN_5;
#else
    //while(RESET == spi_i2s_flag_get(SPI0, SPI_FLAG_TBE));
    //spi_i2s_data_transmit(SPI0, data);
    SPI_DATA(SPI0) = (uint32_t)data;
#endif
#ifdef TEST_SPI_SPEED

    while(RESET == spi_i2s_flag_get(SPI0, SPI_FLAG_TBE));

#endif
    SPI_SM16306S_LE_HIGH;
    //OE_ON;
}

void led_init(void)
{
    spi0_init();
    code38_init();
    //sel_vcc();
#ifdef PWM_LED_OE
    TIME2_Init();
#endif
}




#ifdef PWM_LED_OE

void led_delay()
{
}
#else
void led_delay()
{
    volatile uint32_t i, j;
    OE_ON;
    dev_t.guanggan = adc_buf[0];

    if(dev_t.guanggan > HIGH_V) {
        i = HIGH_V;

    } else if(dev_t.guanggan < LOW_V) {
        i = LOW_V;

    } else {
        i = dev_t.guanggan;
    }

    i = HIGH_V;
#ifdef DEBUG_PWM_LED_ALWAYS_ON
    i = HIGH_V;
#endif
    i = (i - LOW_V) * (34) / (HIGH_V - LOW_V) + 1;

    //}
    //i=(dev_t.guanggan>0xC0)?0xC0:((dev_t.guanggan<20)?20:((dev_t.guanggan-20)*(41-1)/0xC0-20))+1;
    //i=2;//1=10us
    for(; i > 0; i--) {
        for(j = 52; j > 0; j--);
    }

    OE_OFF;
}
#endif
void boot_led_flush(void)
{
    uint8_t i, j;
    spi0_send(0xFFFF);
    spi0_send(0xFFFF);
#ifndef PWM_LED_OE
    dev_t.guanggan = HIGH_V;
#endif

    for(j = 0; j < 200; j++) {
        for(i = 0; i < 8; i++) {
            sel_vcc(i);
            //if(led_array[i][0]||led_array[i][1]){
            led_delay();
            //}
            vTaskDelay(FROM_1_TO_8_DELAY / portTICK_RATE_MS);
        }
    }
}


void led_task(void)
{
    uint8_t i;
    TickType_t xLastWakeTime;
    const TickType_t xPeriod = pdMS_TO_TICKS(FROM_1_TO_8_DELAY);
    xLastWakeTime = xTaskGetTickCount();

    for(i = 0; i < 8; i++) {
        /*#ifdef DEBUG_PWM_LED_ALWAYS_ON
                //timer_disable(TIMER2);
                //if(i==0)
                //TEST_HIGH;
                timer_deinit(TIMER2);
                spi0_send(0xFFFF);
                spi0_send(0xFFFF);
                //timer_enable(TIMER2);
                //TEST_LOW;
                //TEST_HIGH;
                //update_led_bl();
                TIME2_Init();
                //
                sel_vcc(i);
                //if(i==0)
                //TEST_LOW;
                led_delay();
        #else*/
#ifdef PWM_LED_OE
        ;//timer_deinit(TIMER2);
#endif
#ifdef DEBUG_PWM_LED_ALWAYS_ON
        spi0_send(0xFFFF);
        spi0_send(0xFFFF);
#else
        spi0_send(led_array[i][1]);
        spi0_send(led_array[i][0]);
#endif
        sel_vcc(i);
#ifdef PWM_LED_OE
        //TIME2_Init();
        update_led_bl();
#ifdef LCD_PWM_BL
        update_lcd_bl();
#endif
#endif
        //if(led_array[i][0] || led_array[i][1]) {
        led_delay();
        //}
        //TEST_LOW;
        //#endif
        //vTaskDelay(FROM_1_TO_8_DELAY / portTICK_RATE_MS);
        vTaskDelayUntil(&xLastWakeTime, xPeriod);
        //TEST_HIGH;
        //}
    }
}
//volatile uint16_t delay_running;
uint16_t pre_speed;
void compute_speed_value(uint16_t speed_value)
{
    //uint16_t location;
    //uint8_t i;
    uint16_t speed_temp;
    speed_temp = speed_value;

    if(dis_mph) {
        speed_temp = (uint16_t)((float)speed_temp / 1.60934);
        //}else if(dis_mph==2) {
        //speed_temp = (uint16_t)((float)speed_temp / 0.3048);
    }

    if(speed_temp > 199) {
        speed_temp = 199;
    }

    //running led
    /*uint8_t running_led;
    running_led = 200 - speed_temp;
    if(running_led==200){
        //zero
        delay_running = 0;
    }else if((running_led>=1)&&(running_led<=199)){
        delay_running = (running_led+63)/8;//  + 40;
    }*/

    //

    if(pre_speed == speed_temp) {
        return;
    }

    log_debug("in...%d\n", speed_temp);
    speed_in(speed_temp);
    pre_speed = speed_temp;
}


const uint8_t show_7leds_nums[LED_END][7] = {
    {118, 134, 119, 135, 136, 120, 137}, //speed 1
    {121, 138, 123, 139, 140, 122, 141}, //speed 2
    {154, 155, 156, 157, 158, 159, 160}, //mode
    {89, 73, 91, 90, 74, 92, 75}, //bat up 1
    {93, 76, 95, 94, 77, 96, 78}, //bat up 2
    {56, 44, 58, 57, 45, 59, 46}, //bat down 1
    {60, 47, 62, 61, 48, 64, 63}, //bat down 2
    {17, 1, 19, 18, 2, 20, 3}, //range 0
    {21, 5, 23, 22, 6, 24, 7}, //range 1
    {25, 9, 27, 26, 10, 28, 11}, //range 2
    {29, 13, 31, 30, 14, 32, 15}, //range 3
    {225, 241, 226, 242, 171, 227, 243}, //odo 0
    {228, 244, 229, 245, 172, 230, 246}, //odo 1
    {231, 247, 232, 248, 173, 233, 249}, //odo 2
    {193, 209, 194, 210, 174, 195, 211}, //odo 3
    {196, 212, 197, 213, 175, 198, 214}, //odo 4
    {199, 215, 200, 216, 176, 201, 217}, //odo 5
};
//n:0-9:显示数字0-9,0xFF:全灭
void show_7led(uint8_t led_id, uint8_t n)
{
    if(n == 0) {
        LED_ON(show_7leds_nums[led_id][0]);
        LED_ON(show_7leds_nums[led_id][1]);
        LED_ON(show_7leds_nums[led_id][2]);
        LED_OFF(show_7leds_nums[led_id][3]);
        LED_ON(show_7leds_nums[led_id][4]);
        LED_ON(show_7leds_nums[led_id][5]);
        LED_ON(show_7leds_nums[led_id][6]);

    } else if(n == 1) {
        LED_OFF(show_7leds_nums[led_id][0]);
        LED_OFF(show_7leds_nums[led_id][1]);
        LED_OFF(show_7leds_nums[led_id][2]);
        LED_OFF(show_7leds_nums[led_id][3]);
        LED_OFF(show_7leds_nums[led_id][4]);
        LED_ON(show_7leds_nums[led_id][5]);
        LED_ON(show_7leds_nums[led_id][6]);

    } else if(n == 2) {
        LED_OFF(show_7leds_nums[led_id][0]);
        LED_ON(show_7leds_nums[led_id][1]);
        LED_ON(show_7leds_nums[led_id][2]);
        LED_ON(show_7leds_nums[led_id][3]);
        LED_ON(show_7leds_nums[led_id][4]);
        LED_ON(show_7leds_nums[led_id][5]);
        LED_OFF(show_7leds_nums[led_id][6]);

    } else if(n == 3) {
        LED_OFF(show_7leds_nums[led_id][0]);
        LED_OFF(show_7leds_nums[led_id][1]);
        LED_ON(show_7leds_nums[led_id][2]);
        LED_ON(show_7leds_nums[led_id][3]);
        LED_ON(show_7leds_nums[led_id][4]);
        LED_ON(show_7leds_nums[led_id][5]);
        LED_ON(show_7leds_nums[led_id][6]);

    } else if(n == 4) {
        LED_ON(show_7leds_nums[led_id][0]);
        LED_OFF(show_7leds_nums[led_id][1]);
        LED_OFF(show_7leds_nums[led_id][2]);
        LED_ON(show_7leds_nums[led_id][3]);
        LED_OFF(show_7leds_nums[led_id][4]);
        LED_ON(show_7leds_nums[led_id][5]);
        LED_ON(show_7leds_nums[led_id][6]);

    } else if(n == 5) {
        LED_ON(show_7leds_nums[led_id][0]);
        LED_OFF(show_7leds_nums[led_id][1]);
        LED_ON(show_7leds_nums[led_id][2]);
        LED_ON(show_7leds_nums[led_id][3]);
        LED_ON(show_7leds_nums[led_id][4]);
        LED_OFF(show_7leds_nums[led_id][5]);
        LED_ON(show_7leds_nums[led_id][6]);

    } else if(n == 6) {
        LED_ON(show_7leds_nums[led_id][0]);
        LED_ON(show_7leds_nums[led_id][1]);
        LED_ON(show_7leds_nums[led_id][2]);
        LED_ON(show_7leds_nums[led_id][3]);
        LED_ON(show_7leds_nums[led_id][4]);
        LED_OFF(show_7leds_nums[led_id][5]);
        LED_ON(show_7leds_nums[led_id][6]);

    } else if(n == 7) {
        LED_OFF(show_7leds_nums[led_id][0]);
        LED_OFF(show_7leds_nums[led_id][1]);
        LED_ON(show_7leds_nums[led_id][2]);
        LED_OFF(show_7leds_nums[led_id][3]);
        LED_OFF(show_7leds_nums[led_id][4]);
        LED_ON(show_7leds_nums[led_id][5]);
        LED_ON(show_7leds_nums[led_id][6]);

    } else if(n == 8) {
        LED_ON(show_7leds_nums[led_id][0]);
        LED_ON(show_7leds_nums[led_id][1]);
        LED_ON(show_7leds_nums[led_id][2]);
        LED_ON(show_7leds_nums[led_id][3]);
        LED_ON(show_7leds_nums[led_id][4]);
        LED_ON(show_7leds_nums[led_id][5]);
        LED_ON(show_7leds_nums[led_id][6]);

    } else if(n == 9) {
        LED_ON(show_7leds_nums[led_id][0]);
        LED_OFF(show_7leds_nums[led_id][1]);
        LED_ON(show_7leds_nums[led_id][2]);
        LED_ON(show_7leds_nums[led_id][3]);
        LED_ON(show_7leds_nums[led_id][4]);
        LED_ON(show_7leds_nums[led_id][5]);
        LED_ON(show_7leds_nums[led_id][6]);

    } else if(n == 0xFF) {
        LED_OFF(show_7leds_nums[led_id][0]);
        LED_OFF(show_7leds_nums[led_id][1]);
        LED_OFF(show_7leds_nums[led_id][2]);
        LED_OFF(show_7leds_nums[led_id][3]);
        LED_OFF(show_7leds_nums[led_id][4]);
        LED_OFF(show_7leds_nums[led_id][5]);
        LED_OFF(show_7leds_nums[led_id][6]);
    }
}

void update_speed_to_led()
{
    uint8_t num0, num1, num2;
    uint16_t location;
    uint8_t i;
    uint16_t speed_temp;
    static uint16_t pre_speed_hex = 0xFFFF;
    static uint8_t t;
    static uint8_t pre_num1, pre_num2;

    if(speed_out(&speed_temp)) {
        ;//log_debug("out...%d\n", speed_temp);

    } else {
        return;
    }

    //log_debug("delay_running=%d\n",delay_running);
#if 0

    if((pre_speed == speed_temp + 1) || (pre_speed == speed_temp - 1)) {
        t++;

        if(t > 15) {
            t = 0;

        } else {
            if(speed_temp > 3) {
                return;
            }
        }

    } else {
        t = 0;
    }

#endif
    pre_speed_hex = speed_temp;
    //log_debug("speed_temp=%d\n", speed_temp);
    num0 = speed_temp / 100;
    num1 = speed_temp / 10 % 10;
    num2 = speed_temp % 10;

    if(num0 == 1) {
        LED_ON(117);
        LED_ON(133);

    } else {
        LED_OFF(117);
        LED_OFF(133);
    }

#ifdef LINURM_DEBUG_SPEED1

    if(num1 != pre_num1) {
#endif

        switch(num1) {
            case 0:
                if(num0 == 1) {
                    show_7led(SPEED_1, 0);

                } else {
                    show_7led(SPEED_1, 0xFF);
                }

                break;

            case 1:
                show_7led(SPEED_1, 1);
                break;

            case 2:
                show_7led(SPEED_1, 2);
                break;

            case 3:
                show_7led(SPEED_1, 3);
                break;

            case 4:
                show_7led(SPEED_1, 4);
                break;

            case 5:
                show_7led(SPEED_1, 5);
                break;

            case 6:
                show_7led(SPEED_1, 6);
                break;

            case 7:
                show_7led(SPEED_1, 7);
                break;

            case 8:
                show_7led(SPEED_1, 8);
                break;

            case 9:
                show_7led(SPEED_1, 9);
                break;
        }

#ifdef LINURM_DEBUG_SPEED1
        pre_num1 = num1;
    }

    if(num2 != pre_num2) {
#endif

        switch(num2) {
            case 0:
                //if(num0 == 1 || num1 == 1) {
                show_7led(SPEED_2, 0);
                /* } else {
                     LED_OFF(123);
                     LED_OFF(107);
                     LED_OFF(91);
                     LED_OFF(75);
                     LED_OFF(122);
                     LED_OFF(121);
                     LED_OFF(120);
                     LED_OFF(104);
                     LED_OFF(88);
                     LED_OFF(72);
                     LED_OFF(73);
                     LED_OFF(74);
                     LED_OFF(90);
                     LED_OFF(89);
                 }*/
                break;

            case 1:
                show_7led(SPEED_2, 1);
                break;

            case 2:
                show_7led(SPEED_2, 2);
                break;

            case 3:
                show_7led(SPEED_2, 3);
                break;

            case 4:
                show_7led(SPEED_2, 4);
                break;

            case 5:
                show_7led(SPEED_2, 5);
                break;

            case 6:
                show_7led(SPEED_2, 6);
                break;

            case 7:
                show_7led(SPEED_2, 7);
                break;

            case 8:
                show_7led(SPEED_2, 8);
                break;

            case 9:
                show_7led(SPEED_2, 9);
                break;
        }

#ifdef LINURM_DEBUG_SPEED1
        pre_num2 = num2;
    }

#endif
}
void boot_update_speed_led(uint16_t speed_value)
{
    compute_speed_value(speed_value);
    update_speed_to_led();
}


